{ lib, config, ... }:
let
  self = config.flakeDeclared.networking.nixpkgs;
in
{
  options.flakeDeclared.networking.nixpkgs = {
    enable = lib.mkEnableOption "Nixpkgs services connection improvement";
    enableHosts = lib.mkEnableOption "Hosts information for NixOS caches.";
  };
  config = lib.mkIf self.enable {
    nix.settings = {
      substituters = [
        "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
        "https://mirrors.ustc.edu.cn/nix-channels/store"
        "https://mirror.nju.edu.cn/nix-channels/store"
        "https://mirrors.sustech.edu.cn/nix-channels/store"
        "https://mirrors.sjtug.sjtu.edu.cn/nix-channels/store"
        "https://mirrors.cernet.edu.cn/nix-channels/store" # Auto selects among mirror sites.
      ];
      trusted-substituters = [
        "https://mirror.iscas.ac.cn/nix-channels/store" # Occasionally down.
        "https://mirror.nyist.edu.cn/nix-channels/store" # Occasionally down.
        "https://mirrors.cqupt.edu.cn/nix-channels/store" # Cache only.
        "https://nixpkgs-update-cache.nix-community.org"
      ];
      trusted-public-keys = [
        "nixpkgs-update-cache.nix-community.org-1:U8d6wiQecHUPJFSqHN9GSSmNkmdiFW7GW7WNAnHW0SM="
      ];
    };
  };
}
